package com.evil.enterprise.controller;

import com.evil.account.api.RemoteUserRoleService;
import com.evil.common.account.dto.user.role.RoleUsersReqDTO;
import com.evil.common.core.entity.R;
import com.evil.common.log.annotation.RequestLogAnnotation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户角色接口
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/user/role")
public class UserRoleController {

    private final RemoteUserRoleService remoteUserRoleService;

    /**
     * 角色批量删除用户
     *
     * @param roleUsersReqDTO roleUsersReqDTO
     * @return R
     */
    @PostMapping("/batch-delete")
    @RequestLogAnnotation(isSaveRequestData = false, isSaveResponseData = false)
    public R<?> deleteUserRoleBatch(@Validated @RequestBody RoleUsersReqDTO roleUsersReqDTO) {
        roleUsersReqDTO.setEnterpriseId(null);
        remoteUserRoleService.deleteUserRoleBatch(roleUsersReqDTO);
        return R.success();
    }

    /**
     * 角色批量新增用户
     *
     * @param roleUsersReqDTO roleUsersReqDTO
     * @return R
     */
    @PostMapping("/batch-add")
    @RequestLogAnnotation(isSaveRequestData = false, isSaveResponseData = false)
    public R<?> addUserRoleBatch(@Validated @RequestBody RoleUsersReqDTO roleUsersReqDTO) {
        roleUsersReqDTO.setEnterpriseId(null);
        remoteUserRoleService.addUserRoleBatch(roleUsersReqDTO);
        return R.success();
    }
}
